var step = 1;
var style="1";
var sex="1";
var currentlogo="";
var currentsize="";
var logo1="-1";
var logo2="-2";
var logo3="-3";
function search(logo, step) {
	style = $("#style").val();
	sex = $("#sex").val();
	logo1 = $("#logo1").val();
	logo2 = $("#logo2").val();
	logo3 = $("#logo3").val();
	var size1 = $("#size1").val();
	var size2 = $("#size2").val();
	var size3 = $("#size3").val();
	var ename1 = $("#ename1").val();
	var ename2 = $("#ename2").val();
	var ename3 = $("#ename3").val();
	currentlogo = logo1;
	currentsize = size1;
	this.step = step;
	switch (step) {
	case 1:
		if(logo1=="-1"){
			currentlogo="7";
			$("#logo1").val("7");
		}else{
			currentlogo = logo1;
		}
		getShoes("1",currentlogo);
		currentsize = size1;
		removeShoeStyle(currentlogo);
		removeShoeSzieStyle(currentsize);
		$(".content").css("display","block");
		break;
	case 2:
		if(logo2=="-2"){
			if(style=="2"){
				if(sex=="1"){
					$("#logo2").val("43");
					currentlogo = "43";
				}else{
					$("#logo2").val("26");
					currentlogo = "26";
				}
				getShoes("2",currentlogo);
			}else{
				currentlogo="7";
				$("#logo1").val("7");
				getShoes("1",currentlogo);
			}
		}else{
			currentlogo = logo2;
			if(style=="1"){
				getShoes("1",currentlogo);
			}else{
				getShoes("2",currentlogo);
			}
		}
		currentsize = size2;
		removeShoeStyle(currentlogo);
		removeShoeSzieStyle(currentsize);
		$(".content").css("display","block");
		break;
	case 3:
		if(logo3=="-3"){
			if(style=="2"){
				if(sex=="1"){
					$("#logo3").val("43");
					currentlogo = "43";
				}else{
					$("#logo3").val("26");
					currentlogo = "26";
				}
				getShoes("2",currentlogo);
			}else{
				currentlogo="7";
				$("#logo3").val("7");
				getShoes("1",currentlogo);
			}
		}else{
			currentlogo = logo3;
			if(style=="1"){
				getShoes("1",currentlogo);
			}else{
				getShoes("2",currentlogo);
			}
		}
		currentsize = size3;
		removeShoeStyle(currentlogo);
		removeShoeSzieStyle(currentsize);
		$(".content").css("display","block");
		break;
	default:
		break;
	}

	// var sex = document.getElementById("sex").value;
	// window.location.replace("../front/toSearch?step=" + logo.id + "&sex=" +
	// sex);
}
function selectboy() {
	document.getElementById("sex").value = "1";
	document.getElementById("boy").src = "../image/boy_select.png";
	document.getElementById("girl").src = "../image/girl_noselect.png";
}
function selectgirl() {
	document.getElementById("sex").value = "0";
	document.getElementById("boy").src = "../image/boy_noselect.png";
	document.getElementById("girl").src = "../image/girl_select.png";
}

function begintest() {
	
	var logo1 = $("#logo1").val();
	var logo2 = $("#logo2").val();
	var logo3 = $("#logo3").val();
	var size1 = $("#size1").val();
	var size2 = $("#size2").val();
	var size3 = $("#size3").val();
	if(style=="1" && (logo1==logo2 || logo1==logo3 || logo2==logo3)){
		alert("不能选择两个相同的品牌！");
		return;
	}
	$.post("../front/getResult", {
		logo1 : logo1,
		logo2 : logo2,
		logo3 : logo3,
		size1 : size1,
		size2 : size2,
		size3 : size3,
		sex:sex
	}, function(data) {
		if(data.msg=="y"){
			window.location.replace("../front/toResult");
		}else{
			alert(data.msg);
		}
		
	});
}



//选中某双鞋子时到后台获取该鞋子对应的鞋码
function getShoes(type,currentlogo) {
	
	//removeShoeStyle(id);

	$.post("../front/getShoesByType", {
		type : type
	}, function(data) {
		var list = eval(data);
		var ul = document.getElementById("shoe");
		var html = '';
		for (var i = 0; i < list.length; i++) {
			html += '<li  style="position: relative;margin-right: 0px; width: 80px;height:80px;" atr="'+list[i].id+'" onclick=selShoeSize('+list[i].id+',\''+list[i].en_name+'\')><img src="../image/logo/'+list[i].en_name+'.png"/><div style="display:none;position: absolute;width: 60px;height: 60px;top:10px;left:4px;background-color: #000000;filter:alpha(opacity=10);-moz-opacity:0.1;opacity:0.1;border: 1px solid #e3e3e3;-moz-border-radius: 50%;-webkit-border-radius: 50%;border-radius:50%; "></div></li>';
		}
		ul.innerHTML = '';
		ul.innerHTML += html;
		
		$('#carousel1').elastislide({
			imageW : 90,
			border : 0,
		});
			selShoeSize(currentlogo,ename1);//获取鞋码
			if(step=="1"){
				removeShoeStyle($("#logo1").val());
				removeShoeSzieStyle($("#size1").val());
			}else if(step=="2"){
				removeShoeStyle($("#logo2").val());
				removeShoeSzieStyle($("#size2").val());
			}if(step=="3"){
				removeShoeStyle($("#logo3").val());
				removeShoeSzieStyle($("#size3").val());
			}
	});
}



//选中某双鞋子时到后台获取该鞋子对应的鞋码
function selShoeSize(id, ename) {
	var url="../front/getSizeByLogo";
	if(style=="2" && (step==2||step==3)){
		url="../front/getSizeByLogoForNoSport";
	}
	removeShoeStyle(id);

	$.post(url, {
		logo : id
	}, function(data) {
		var list = eval(data);
		var ul = document.getElementById("shoesize");
		var html = '';
		for (var i = 0; i < list.length; i++) {
			html += '<li atr="' + list[i].french_size + '"  style="cursor:pointer;margin-right: 0px; width: 40px;" onclick="selFinish(this,' + list[i].french_size + ',\''
					+ ename + '\')"><img style="display:none" src="../image/1.jpg"/><a>' + list[i].french_size + '</a></li>';
		}
		ul.innerHTML = '';
		ul.innerHTML += html;
		document.getElementById("carousel2").style.display = "block";
		document.getElementById("logo" + step).value = id;
		document.getElementById("ename" + step).value = ename;
		$('#carousel2').elastislide({
			imageW : 60,
			border :1
		});
			if(step=="1"){
				removeShoeStyle($("#logo1").val());
				removeShoeSzieStyle($("#size1").val());
			}else if(step=="2"){
				removeShoeStyle($("#logo2").val());
				removeShoeSzieStyle($("#size2").val());
			}if(step=="3"){
				removeShoeStyle($("#logo3").val());
				removeShoeSzieStyle($("#size3").val());
			}
	});
}

function selFinish(obj, size, ename) {
	//removeShoeSzieStyle(size);
	document.getElementById("size" + step).value = size;
	if(style=="1"){
		document.getElementById(step).src = "../image/yundong/" + size + ".png";
	}else{
		if(step==1){
			document.getElementById(step).src = "../image/yundong/" + size + ".png";
		}else{
			document.getElementById(step).src = "../image/pixie/" + size + ".png";
		}
	}
	$(".content").css("display","none");
	var logo1 = $("#logo1").val();
	var logo2 = $("#logo2").val();
	var logo3 = $("#logo3").val();
	var size1 = $("#size1").val();
	var size2 = $("#size2").val();
	var size3 = $("#size3").val();
	if(logo1!="-1" && logo2!="-2" && logo3!="-3" && size1!=""&& size1!=undefined &&size2!=""&&size2!=undefined&&size3!=""&&size3!=undefined){
		$("#finish").css("display","block");
	}
}
//选中传入id的鞋码，其余的取消高亮
function removeShoeStyle(id) {
	var width=$("#carousel1").width();
	var shoewidth=$("#shoe").width();
//	if(shoewidth>=1024){
		$("#shoe").css({"width":"100%"});
		$("#shoesize").css({"width":"100%"});
//	}else{
		//$("#shoe").css({"height":"90px","margin-left":(width-shoewidth)/2+"px"});
	//}
	$("#shoe li").each(function(index, e) {
		if ($(this).attr("atr") == id) {
			//$(this).css({"margin-top":"-5px","width":"80px","height":"80px"});
			$(this).find("div").css("display","block");
		} else {
			//$(this).css({"width":"50px","height":"50px","margin-top":"20px"});
			$(this).find("div").css("display","none");
		}
	});
	
	
}
//选中传入size的鞋码，其余的取消高亮
function removeShoeSzieStyle(size) {
//	$("#shoesize li").each(function(index, e) {
//		if ($(this).attr("atr") == size) {
//			$(this).css("background-color", "#e0690c");
//		} else {
//			$(this).css("background-color", "#ffffff");
//		}
//	});
}